#include "copyright.h"
#include "system.h"
#include "Table.h"

table = new Table(tablesize);
//here goes the test code
void tableProducer(int which){
  while(true){
    int *item = new int[1];
    item[0]=Random();
    printf("%s produced %d in %d\n",CurrentThread->getName(),item[0],table->Alloc(item));
  }
}
void tableConsumer(int which){
    while(true){
        void *point=table->Get(table->CurrentPoint);
        table->Release(table->CurrentPoint);
        printf("%s comsumed %d in %d\n",CurrentThread->getName(),*(int *)point,table->CurrentPoint);
    }
}
void tableTestOrigin(int tablesize,int ProducerNum,int ConsumerNum){
    DEBUG('t',"Debugging the Table");
    //producer threads
    for(int i = 0;i<ProducerNum;i++){
        char *threadName = new char[20];
        strcat(name,"producer thread ");
        i=i+48;
        strcat(name,i);
        i=i-48;
        Thread *t = new Thread(name);
        t->Fork(tableProducer,0);
    }
    //consumer threads
    for(int i = 0;i<ConsumerNum;i++){
        char *threadName = new char[20];
        strcat(name,"consumer thread ");
        i=i+48;
        stract(name,i);
        i=i-48;
        Thread *t = new Thread(name);
        t->Fork(tableConsumer,0);
    }
}
// use for other space
void tableTest(){
    int tablesize,ProducerNum,ConsumerNum;
    printf("plz tell me tablesize,producernum and consumernum =?\n");
    scanf("%d",tablesize);
    scanf("%d",ProducerNum);
    scanf("%d",ConsumerNum);
    tableTestOrigin(tablesize,ProducerNum,ConsumerNum);
}